package psd.scala.rules
import scala.collection.mutable 
import psd.scala.FactDb
import psd.model.Bug


class CompositeRule (description: String) extends AbstractRule(description) {

  val rules = List[AbstractRule]()
  
  def execute(db: FactDb): mutable.ArrayBuffer[Bug]= {
	   var compositeRuleBugs = new mutable.ArrayBuffer[Bug]
	   var ruleSatisfied = true;
	   
	   for(rule <- rules) {
	     val bugs = rule.execute(db)
	     if (bugs.size == 0)
	       ruleSatisfied = false
	       else
	         compositeRuleBugs.appendAll(bugs)
	   }
	   
	    var compositeBugs = new mutable.ArrayBuffer[Bug]
	    if (ruleSatisfied) {
	    	val compositeBug = new Bug;
			compositeBug.set_description(this.description);
			compositeBug.set_lineNumber(compositeRuleBugs(0).get_lineNumber());
			compositeBug.set_path(compositeRuleBugs(0).get_path());
			compositeBugs+=(compositeBug);
	    }
	    
	   return compositeBugs
  }
  
  
}